﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Manon.Repository.Extensions
{
    public static class DbEntityHelper
    {

        /// <summary>
        /// 获取表名
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <returns></returns>
        public static string GetTableName<TEntity>() where TEntity : class, new()
        {
            Type entityType = typeof(TEntity);
            string tableName = entityType.Name;
            var tableAttri = entityType.GetCustomAttribute<TableAttribute>();
            if (tableAttri != null)
            {
                tableName = tableAttri.Name;
            }
            return tableName;
        }
    }
}
